﻿/** --弹出广告-- **/
function createPopHtml(){
	var _h  ='<div class="ad_win">'
    		+'	<a id="ad_link" href="#" target="_blank">'
    		+'		<img id="ad_img" width="750" height="400" src="img/advertisement.jpg" border="0" />'
    		+'	</a>'
			+'		<span onclick="close_win()" class="ac_close_btn">关闭</span>'
			+'</div>';
	if($('.ad_win').length==0){
		$('body').append(_h);
	}
}
function popStart(popImg,popUrl){
	createPopHtml();
	var date = getDate()%3;
	switch(date)
	   {
	   case 0:
		 $('#ad_img').attr('src',popImg[0]);//小学
		 $('#ad_link').attr('href',popUrl[0]);
		 break
	   case 1:
		 $('#ad_img').attr('src',popImg[1]);//初中
		 $('#ad_link').attr('href',popUrl[1]);
		 break
	   case 2:
		 $('#ad_img').attr('src',popImg[2]);//高中
		 $('#ad_link').attr('href',popUrl[2]);
		 break
	   }
	var width = $('.ad_win').width()/2;
	var height = $('.ad_win').height()/2;
	var top = ($(window).height()/2)-height;
	var left= ($(window).width()/2)-width;
	$('.ad_win').css({top:top+'px',left:left+'px'});
	$('.ad_win').show();
	setTimeout(function(){
		$('.ad_win').animate({ 
				top:-($('.ad_win').height()),
				opacity: 'hide'
		}, 500 );
	},5000);
}
function close_win(){
	$(".ad_win").hide();
}
function getDate(){
	var slash = "/";  
    var dateStr = "2011-11-11";//开始时间  
    var reg = /^(\d{4})-(\d{2})-(\d{2})$/;  
    var yyyyMMdd = reg.exec(dateStr);  
    var startDate  = Date.parse(yyyyMMdd[2] + slash + yyyyMMdd[3] + slash + yyyyMMdd[1]);  
	//获取当前时间戳
	var curr_time = new Date();
	var endDate  = curr_time.getYear()+1900+"-";
	endDate  += curr_time.getMonth()+1+"-";
	endDate  += curr_time.getDate(); 
	yyyyMMdd = reg.exec(endDate);
	endDate = Date.parse(yyyyMMdd[2] + slash + yyyyMMdd[3] + slash + yyyyMMdd[1]);  
	var date = (endDate-startDate)/(1000*60*60*24);
	return date;
}
$(window).scroll(function(){
	var width = $('.ad_win').width()/2;
	if(!window.XMLHttpRequest){
		$(".ad_win").css('top',$(window).scrollTop()+$(window).height()-width);
	}
});
/** --弹出广告-- **/